 (define-module (test-packages)
 	       #:use-module (gnu packages version-control)
 	       #:use-module (gnu packages suckless)
 	       #:use-module (gnu packages emacs)
 	       #:use-module (gnu packages sqlite)
 	       #:use-module (gnu packages)
 	       #:use-module (guix parameters)
 	       #:use-module (guix packages)
 	       #:use-module (guix utils)
 	       #:use-module (guix git-download)
 	       #:use-module (guix build-system gnu))

 (define-global-parameter
   (package-parameter
     (name 'tests)
     (variants
       (parameter-variant-match
 	(_ #:lambda (lambda (pkg)
 		      (display "Something expected!")
 		      (newline) pkg)
 	   #:lambda (lambda (pkg pv)
 		      (display "Something else expected!\n")
 		      pkg))
 	(off #:lambda (lambda (pkg) (display "One more test!\n") pkg)
 	     #:transform (without-tests #:package-name)
 	     #:lambda (lambda (pkg pv) (display "Global parameters work!!! ")
 			(display pv)
 			(newline) pkg)
 	     (lambda (pkg) (display "one more thing...\n") pkg))))
     (description "toggle for tests")
     (predicate (const #t)))) ;(lambda (pkg)
 ; (eqv? (package-build-system pkg)
 ;      gnu-build-system)))))

  (define-public git-st
  	       (package-with-parameters
  		 ;; pspec
  		 (parameter-spec
  		   (local
  		     (list
  		       ;; (package-parameter
  		       ;;   (name 'temp)
  		       ;;   (type (parameter-type
  		       ;; 	  (name 'temp-type)
  		       ;; 	  (accepted-values '(1 2 3)))))
  		       (package-parameter
  			 (name 'git)
  			 (variants
  			   (parameter-variant-match
  			     (off #:lambda (lambda (pkg pv) (display "IT WORKS! ") (display pv) (newline) pkg))
  			     (on #:transform (with-git-url #:package-name "https://github.com/cel7t/st")))))))
  		   (defaults '((git off))))
  		 (inherit st)
  		 (arguments (parameter-if (git) ; (list (cons 'git 'on))
  					  (and (display "Parameter-if works\n")
  					       (package-arguments st))
  					  (and (display "INITIAL Parameter-if works\n")
  					       (package-arguments st))))
  		 (name "git-st")))

(define-global-parameter
  (package-parameter
    (name 'x11)))

(define-public emacs-p
               (package-with-parameters
                 [parameter-spec
                   (local
                     (list
                       (package-parameter
                         (name 'next)
                         (variants
                           (parameter-variant-match
                             (_ #:lambda (lambda (pkg)
                                           (package
                                             (inherit pkg)
                                             (version "29.0.92")
                                             (source
                                               (origin
                                                 (inherit (package-source pkg))
                                                 (method git-fetch)
                                                 (uri (git-reference
                                                        (url "https://git.savannah.gnu.org/git/emacs.git/")
                                                        (commit (string-append "emacs-" version))))
                                                 (file-name (git-file-name (package-name pkg) version))
                                                 (patches
                                                   (parameter-if #:package pkg (pgtk)
                                                                 (search-patches
                                                                   "emacs-exec-path.patch"
                                                                   "emacs-fix-scheme-indent-function.patch"
                                                                   "emacs-native-comp-driver-options.patch"
                                                                   "emacs-pgtk-super-key-fix.patch")
                                                                 (search-patches
                                                                   "emacs-exec-path.patch"
                                                                   "emacs-fix-scheme-indent-function.patch"
                                                                   "emacs-native-comp-driver-options.patch")))
                                                 (sha256
                                                   (base32
                                                     "1h3p325859svcy43iv7wr27dp68049j9d44jq5akcynqdkxz4jjn"))))))))))
                       (package-parameter (name 'tree-sitter)
                                          (dependencies '(tree-sitter)))
                       (package-parameter
                         (name 'pgtk)
                         (variants
                           (parameter-variant-match
                             (_ #:transform (with-configure-flag
                                              #:package-name "=--with-pgtk"))))
                         (dependencies '(tree-sitter x11)))
                       (package-parameter
                         (name 'xwidgets)
                         (variants
                           (parameter-variant-match
                             (_ #:transform (with-configure-flag
                                              #:package-name "=--with-xwidgets")))))
                       (package-parameter
                         (name 'wide-int)
                         (variants
                           (parameter-variant-match
                             (_ #:transform (with-configure-flag
                                              #:package-name "=--with-wide-int")))))))
                   (one-of '((_ (x11 #:off) pgtk)
                             (_ (x11 #:off) xwidgets)))]
                 (inherit emacs)
                 (name "emacs-p")
                 (arguments
                   (parameter-substitute-keyword-arguments
                     (package-arguments emacs)
                     [((x11 #:off))
                      '(((#:configure-flags flags #~'())
                         #~(delete "--with-cairo" #$flags))
                        ((#:modules _) (%emacs-modules build-system))
                        ((#:phases phases)
                         #~(modify-phases #$phases
                                          (delete 'restore-emacs-pdmp)
                                          (delete 'strip-double-wrap))))]
                     [(#:all (xwidgets on) (pgtk #:off))
                      '(((#:configure-flags flags #~'())
                         #~(cons "--with-xwidgets" #$flags))
                        ((#:modules _) (%emacs-modules build-system))
                        ((#:phases phases)
                         #~(modify-phases #$phases
                                          (delete 'restore-emacs-pdmp)
                                          (delete 'strip-double-wrap))))]))
                 (inputs
                   (parameter-modify-inputs (package-inputs emacs)
                                            ((next) (prepend sqlite))
                                            (((tree-sitter on)) (prepend tree-sitter))
                                            (((xwidgets on)) (prepend gsettings-desktop-schemas
                                                                      webkitgtk-with-libsoup2))
                                            (((x11 #:off))
                                             (delete "libx11" "gtk+" "libxft" "libtiff" "giflib" "libjpeg"
                                                     "imagemagick" "libpng" "librsvg" "libxpm" "libice" "libsm"
                                                     "cairo" "pango" "harfbuzz" "libotf" "m17n-lib" "dbus"))))))
